import logging
import time

import pytest

from resource.pom.music import Music


class Test:
    app = Music

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1：点击音乐应用')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        device.stop_permission()
        logging.info('预期结果1.正常进入音乐应用内')
        device.assert_current_window(self.app.window_name)

        logging.info('步骤2.左右滑动音乐播放进度条')
        device.refresh_layout()
        play = device.get_element_by_key('image3')
        device.swipe(100, 979, 500, 979)
        device.refresh_layout()
        slider = device.get_element_by_type('Slider')
        text1 = slider.get('text')

        device.swipe(500, 979, 100, 979)
        device.refresh_layout()
        slider = device.get_element_by_type('Slider')
        text2 = slider.get('text')
        device.click_element(play)
        logging.info('预期结果2.音乐播放进度条可前后调整，调整后可正常播放')
        device.refresh_layout()

        logging.info('进度条拖动前后的值分别为{}，{}'.format(text1, text2))
        assert float(text1) > float(text2), '进度条的的值未正确变化'
        device.assert_text_exist('00:00', expect=False)
        assert device.is_audio_running(), '音乐没有声音输出'
